package cn.tedu.jsd2209.csmall.product.service.impl;

import cn.tedu.jsd2209.csmall.product.ex.ServiceException;
import cn.tedu.jsd2209.csmall.product.mapper.AlbumMapper;
import cn.tedu.jsd2209.csmall.product.pojo.dto.AlbumAddNewDTO;
import cn.tedu.jsd2209.csmall.product.pojo.entity.Album;
import cn.tedu.jsd2209.csmall.product.service.IAlbumService;
import cn.tedu.jsd2209.csmall.product.web.ServiceCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class AlbumServiceImpl implements IAlbumService {
    @Autowired
    private AlbumMapper albumMapper;
    @Override
    public void addNew(AlbumAddNewDTO albumAddNewDTO) {
        int count = albumMapper.countByName(albumAddNewDTO.getName());
        if (count>0){
            String message = "添加失败,相册名字重复";
            throw new ServiceException(ServiceCode.ERR_CONFLICT,message);
        }
        Album album = new Album();
        BeanUtils.copyProperties(albumAddNewDTO,album);
        int insert = albumMapper.insert(album);

    }
}
